<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: file object</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_file.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">file object </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptfile/</p>
<p>This object provides support for reading and writing files.</p>
<p>Register with <code>RegisterScriptFile(asIScriptEngine*)</code>.</p>
<p>If you do not want to provide write access for scripts then you can compile the add on with the define AS_WRITE_OPS 0, which will disable support for writing. This define can be made in the project settings or directly in the header.</p>
<h2><a class="anchor" id="doc_addon_file_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CScriptFile
{
<span class="keyword">public</span>:
  <span class="comment">// Constructor</span>
  CScriptFile();

  <span class="comment">// Memory management</span>
  <span class="keywordtype">void</span> AddRef() <span class="keyword">const</span>;
  <span class="keywordtype">void</span> Release() <span class="keyword">const</span>;

  <span class="comment">// Opening and closing file handles</span>
  <span class="comment">// mode = &quot;r&quot; -&gt; open the file for reading</span>
  <span class="comment">// mode = &quot;w&quot; -&gt; open the file for writing (overwrites existing files)</span>
  <span class="comment">// mode = &quot;a&quot; -&gt; open the file for appending</span>
  <span class="keywordtype">int</span> Open(<span class="keyword">const</span> std::string &amp;filename, <span class="keyword">const</span> std::string &amp;mode);
  <span class="keywordtype">int</span> Close();
  
  <span class="comment">// Returns the size of the file</span>
  <span class="keywordtype">int</span> GetSize() <span class="keyword">const</span>;
  
  <span class="comment">// Returns true if the end of the file has been reached</span>
  <span class="keywordtype">bool</span> IsEOF() <span class="keyword">const</span>;

  <span class="comment">// Reads a specified number of bytes into the string</span>
  <span class="keywordtype">int</span> ReadString(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, std::string &amp;str);
  
  <span class="comment">// Reads to the next new-line character</span>
  <span class="keywordtype">int</span> ReadLine(std::string &amp;str);

  <span class="comment">// Reads a signed integer</span>
  <a class="code" href="angelscript_8h.html#aa8044b56ee56e2350b06f1e7207b43df" title="64 bit integer">asINT64</a>  ReadInt(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> bytes);

  <span class="comment">// Reads an unsigned integer</span>
  <a class="code" href="angelscript_8h.html#a10aea5de212e440ffd6ec8fc0b17563d" title="64 bit unsigned integer">asQWORD</a>  ReadUInt(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> bytes);

  <span class="comment">// Reads a float</span>
  <span class="keywordtype">float</span>    ReadFloat();

  <span class="comment">// Reads a double</span>
  <span class="keywordtype">double</span>   ReadDouble();
    
  <span class="comment">// Writes a string to the file</span>
  <span class="keywordtype">int</span> WriteString(<span class="keyword">const</span> std::string &amp;str);
  
  <span class="keywordtype">int</span> WriteInt(<a class="code" href="angelscript_8h.html#aa8044b56ee56e2350b06f1e7207b43df" title="64 bit integer">asINT64</a> v, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> bytes);
  <span class="keywordtype">int</span> WriteUInt(<a class="code" href="angelscript_8h.html#a10aea5de212e440ffd6ec8fc0b17563d" title="64 bit unsigned integer">asQWORD</a> v, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> bytes);
  <span class="keywordtype">int</span> WriteFloat(<span class="keywordtype">float</span> v);
  <span class="keywordtype">int</span> WriteDouble(<span class="keywordtype">double</span> v);

  <span class="comment">// File cursor manipulation</span>
  <span class="keywordtype">int</span> GetPos() <span class="keyword">const</span>;
  <span class="keywordtype">int</span> SetPos(<span class="keywordtype">int</span> pos);
  <span class="keywordtype">int</span> MovePos(<span class="keywordtype">int</span> delta);

  <span class="comment">// Determines the byte order of the binary values (default: false)</span>
  <span class="comment">// Big-endian = most significant byte first</span>
  <span class="keywordtype">bool</span> mostSignificantByteFirst;
};
</pre></div><h2><a class="anchor" id="doc_addon_file_2"></a>
Public script interface</h2>
<pre>
  class file
  {
    int      open(const string &amp;in filename, const string &amp;in mode);
    int      close();
    int      getSize() const;
    bool     isEndOfFile() const;
    int      readString(uint length, string &amp;out str);
    int      readLine(string &amp;out str);
    int64    readInt(uint bytes);
    uint64   readUInt(uint bytes);
    float    readFloat();
    double   readDouble();
    int      writeString(const string &amp;in string);
    int      writeInt(int64 value, uint bytes);
    int      writeUInt(uint64 value, uint bytes);
    int      writeFloat(float value);
    int      writeDouble(double value);
    int      getPos() const;
    int      setPos(int pos);
    int      movePos(int delta);
    bool     mostSignificantByteFirst;
  }
</pre><h2><a class="anchor" id="doc_addon_file_3"></a>
Script example</h2>
<pre>
  file f;
  // Open the file in 'read' mode
  if( f.open("file.txt", "r") &gt;= 0 ) 
  {
      // Read the whole file into the string buffer
      string str;
      f.readString(f.getSize(), str); 
      f.close();
  }
</pre> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
